import {createRouter, createWebHashHistory, createWebHistory, Router} from 'vue-router';
import routes from './routes';
import wx from 'weixin-js-sdk'
const baseFix = import.meta.env.VITE_APP_BASE_PREFIX;

const router: Router = createRouter({
  // hash: ,
  // todo
  // history: createWebHistory(''),
  history: createWebHashHistory(baseFix),
  routes: routes,
});

router.beforeEach(async (_to, _from, next) => {
  if((_from.name === 'mainMenu' || _from.name === 'mainMenu_tea') && (_to.name === 'loginC' || _to.name === 'load')){
    wx.closeWindow();
  }
  // else if(_from.name === 'ttsq' && (_to.name === 'stop' || _to.name === 'add')){
  //   next({ name: 'mainMenu_tea' })
  // }else {
    next();
  // }
});

export default router;
